<?php
class Index extends Action {
	private $limit = 15;
	/*
	 * (non-PHPdoc) @see Action::execute()
	 */
	public function execute($params) {
		check_login ( ADMIN_LOGIN_PAGE );
		$data = array ();
		$start = rqst ( 'start', 1 ); // 分页
		$where = Model::where_build ( array ('name like','title like' ), $data, array ('name' => 'like','title like' ) );
		$wfM = new WebFragmentModel ();
		
		$wfM->sort ( array ('fragment_id','d' ) );
		
		$wfM->where ( $where )->limit ( $this->limit, $start - 1 )->count ( true );
		$items = $wfM->retrieve ();
		$totalCount = 0;
		if ($items) {
			$data ['items'] = $items;
			$totalCount = $items->countTotal;
		} else {
			$data ['items'] = array ();
		}
		$data ['totalCount'] = $totalCount;
		$data ['limit'] = $this->limit;
		$data ['curl'] = $this->url;
		$data ['navi'] = 'fragment';
		$data ['page_tip_info'] = sess_del ( 'page_tip_info' );
		
		bind ( 'get_fragment_bench_options', array ($this,'get_fragment_bench_options' ) );
		bind ( 'get_fragment_operation', array ($this,'get_fragment_operation' ), 1, 2 );
		return new SmartyView ( $data, 'fragment/Index' );
	}
	public function get_fragment_bench_options($opt) {
		$opt .= '<li><a href="#" class="del-all-fragment"><i class="icon-trash"></i>删除</a></li>';
		return $opt;
	}
	public function get_fragment_operation($opts, $item) {
		$opts .= '<a href="./?Ctlr=EditFrag&fid=' . $item ['fragment_id'] . '"><i class="icon-edit"></i></a>';
		$opts .= '<a onclick="return confirm(\'你确定要删除该代码片断?\');" href="./?Ctlr=DelFrag&fid=' . $item ['fragment_id'] . '"><i class="icon-trash"></i></a>';
		return $opts;
	}
}